package webservices;

import interfaces.ISlideQuery;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import webservices.helper.Helper;

public class SlideQueryImpl implements ISlideQuery {

	@Override
	public String query(String courseID) {
		String returnMessage = "";
		Connection con = null;
		try {
			con = Helper.getDBConnection();
			
			returnMessage = "<response name='success' />";
			ResultSet rs = null;
			rs = con.createStatement().executeQuery("select * from slide where courseid = " + courseID);

			while (rs.next()){
				returnMessage += "<response name='slide'>";
				returnMessage += "<slideID>" + rs.getString("slideID") + "</slideID>";
				returnMessage += "<name>" + rs.getString("name") + "</name>";
				returnMessage += "<description>" + rs.getString("description") + "</description>";
				returnMessage += "<link>" + rs.getString("link") + "</link>";
				returnMessage += "</response>";
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try{
				con.close();
			}catch(SQLException e) {}
		}
		return returnMessage;
	}
}
